from typing import Optional

from apps.app_auth_provider.models import AuthProvider, AuthProviderType


class AuthProviderManager:
    @staticmethod
    def get_auth_provider(provider_type: str) -> Optional[AuthProvider]:
        return AuthProvider.objects.filter(provider_type=provider_type).first()

    @staticmethod
    def create_auth_provider(
            name: str,
            provider_type: str,
            client_id: str,
            client_secret: str,
            endpoint_url: str,
            meta_url: str,
            callback_url: str = '',
            is_active: bool = True,
            description: str = ''
    ) -> AuthProvider:
        obj = AuthProvider(
            name=name,
            provider_type=provider_type,
            client_id=client_id,
            client_secret=client_secret,
            endpoint_url=endpoint_url,
            meta_url=meta_url,
            callback_url=callback_url,
            is_active=is_active,
            description=description
        )
        obj.save(force_insert=True)
        return obj
